package com.bawei.module_service.ui.patrol

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.bawei.lib_common.Router
import com.bawei.lib_common.base.BaseActivity
import com.bawei.lib_common.base.BaseViewModel
import com.bawei.lib_common.base.state.Empty
import com.bawei.lib_common.base.state.Failed
import com.bawei.lib_common.base.state.Loading
import com.bawei.lib_common.base.state.Success
import com.bawei.lib_common.observeWithLifecycle
import com.bawei.lib_common.utils.ToastUtils
import com.bawei.module_service.R
import com.bawei.module_service.adapter.MaintainAdapter
import com.bawei.module_service.adapter.PatrolAdapter
import com.bawei.module_service.databinding.ActivityPatrolManagerBinding
import com.bawei.module_service.http.ServiceViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = Router.PATROL_MANAGER_PAGE)
class PatrolManagerActivity : BaseActivity<BaseViewModel,ActivityPatrolManagerBinding>() {
    override val mLayoutResId: Int
        get() = R.layout.activity_patrol_manager
    val mAdapter: PatrolAdapter by lazy {
        PatrolAdapter()
    }
    private val mViewModel: ServiceViewModel by viewModels()
    override fun initView() {
        super.initView()
        mBinding.rvList.adapter=mAdapter
        mBinding.rvList.layoutManager= LinearLayoutManager(this)
    }

    override fun initData() {
        super.initData()
        mViewModel.getPatrolList()
    }

    override fun initListener() {
        super.initListener()
        mViewModel.mPatrol.observeWithLifecycle(this){
            when(it){
                Empty -> {}
                is Failed -> {
                    ToastUtils.showLong(this,it.message)
                }
                Loading -> {}
                Success -> {
                    mAdapter.setData(mViewModel.mPatrolList)
                }
            }
        }
    }

    override fun initStatusBar() {
        super.initStatusBar()
    }

}